from django.db import models
from django.contrib.auth.models import User
from django.db.models import permalink
from datetime import datetime

# Create your models here.

class Character(models.Model):
    player = models.ForeignKey(User)
    name = models.CharField("Character's name",maxlength=200)
    created_on = models.DateTimeField('Date created', default=datetime.now())
    
    def get_absolute_url(self):
        return ('characters.views.details', [str(self.id)])
    
    get_absolute_url = permalink(get_absolute_url)
    
    def __repr__(self):
        return self.name
    
    def __str__(self):
        return self.name
    
    class Admin:
        list_display = ('name', 'created_on')

class BackgroundType(models.Model):
    name = models.CharField(maxlength=100)
    
    def __repr__(self):
        return self.name
    
    def __str__(self):
        return self.name
    
    class Admin:
        pass
    
    class Meta:
        ordering = ['name']

class Background(models.Model):
    type = models.ForeignKey(BackgroundType, core=True)
    character = models.ForeignKey(Character, edit_inline=models.TABULAR, core=True)
    level = models.SmallIntegerField(core=True)
    
    def __repr__(self):
        return "%s %s" % (self.type, self.level)
    
    def __str__(self):
        return "%s %s" % (self.type, self.level)
    
    class Admin:
        list_display = ('type', 'character', 'level',)

class InfluenceType(models.Model):
    name = models.CharField(maxlength=100)
    
    def __repr__(self):
        return self.name
    
    def __str__(self):
        return self.name
    
    class Admin:
        pass
    
    class Meta:
        ordering = ['name']
        
class Influence(models.Model):
    type = models.ForeignKey(InfluenceType, core=True)
    character = models.ForeignKey(Character, edit_inline=models.TABULAR, core=True)
    level = models.SmallIntegerField(core=True)
    
    def __repr__(self):
        return "%s %s" % (self.type, self.level)
    
    def __str__(self):
        return "%s %s" % (self.type, self.level)
    
    class Admin:
        list_display = ('type', 'character', 'level',)
